package com.ulook.lookplanet.data.source;

import com.ulook.lookplanet.common.AppServer;
import com.ulook.lookplanet.data.model.TUser;
import com.ulook.lookplanet.data.repository.LoginRepository;
import com.ulook.lookplanet.util.ThrowException;
import com.ulook.lookplanet.util.net.AsynRequestUtil;
import com.ulook.lookplanet.util.net.RequestParams;
import com.ulook.lookplanet.util.net.ResponseCallback;

/**
 * Class that handles authentication w/ login credentials and retrieves user information.
 * 该类处理带有登录凭据的身份验证并检索用户信息。
 */
public class LoginDataSource{

    public LoginDataSource(){ }

    /**
     * 处理登陆后的用户信息
     */
    public void login(String username, String password, ResponseCallback callback) {
        //LoggedInUser fakeUser = new LoggedInUser(java.util.UUID.randomUUID().toString(),"Jane Doe");
        RequestParams params = new RequestParams();
        params.put("id", username);
        params.put("password", password);
        AsynRequestUtil.post(AppServer.ROOT_PATH+"/login", params, TUser.class, callback);
    }

    /**
     * 注册账号
     */
    public void register(String nickname, String username, String password, ResponseCallback callback){
        RequestParams params = new RequestParams();
        params.put("name", nickname);
        params.put("id", username);
        params.put("password", password);
        AsynRequestUtil.post(AppServer.ROOT_PATH+"/register", params, TUser.class, callback);
    }

    /**
     * 撤销身份验证
     */
    public void logout() {
        // TODO: 撤销身份验证
    }


}